
package cn.edu.scau.cmi.hombio.dao;

import cn.edu.scau.cmi.hombio.domain.TaskIntervalCycle;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage TaskIntervalCycle entities.
 * 
 */
@Repository("TaskIntervalCycleDAO")

@Transactional
public class TaskIntervalCycleDAOImpl extends AbstractJpaDao<TaskIntervalCycle> implements TaskIntervalCycleDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] {
			TaskIntervalCycle.class }));

	/**
	 * EntityManager injected by Spring for persistence unit pig
	 *
	 */
	@PersistenceContext(unitName = "pig")
	private EntityManager entityManager;

	/**
	 * Instantiates a new TaskIntervalCycleDAOImpl
	 *
	 */
	public TaskIntervalCycleDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByMemo
	 *
	 */
	@Transactional
	public Set<TaskIntervalCycle> findTaskIntervalCycleByMemo(String memo) throws DataAccessException {

		return findTaskIntervalCycleByMemo(memo, -1, -1);
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByMemo
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TaskIntervalCycle> findTaskIntervalCycleByMemo(String memo, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTaskIntervalCycleByMemo", startResult, maxRows, memo);
		return new LinkedHashSet<TaskIntervalCycle>(query.getResultList());
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByPrimaryKey
	 *
	 */
	@Transactional
	public TaskIntervalCycle findTaskIntervalCycleByPrimaryKey(Integer id) throws DataAccessException {

		return findTaskIntervalCycleByPrimaryKey(id, -1, -1);
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByPrimaryKey
	 *
	 */

	@Transactional
	public TaskIntervalCycle findTaskIntervalCycleByPrimaryKey(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findTaskIntervalCycleByPrimaryKey", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.TaskIntervalCycle) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findTaskIntervalCycleById
	 *
	 */
	@Transactional
	public TaskIntervalCycle findTaskIntervalCycleById(Integer id) throws DataAccessException {

		return findTaskIntervalCycleById(id, -1, -1);
	}

	/**
	 * JPQL Query - findTaskIntervalCycleById
	 *
	 */

	@Transactional
	public TaskIntervalCycle findTaskIntervalCycleById(Integer id, int startResult, int maxRows) throws DataAccessException {
		try {
			Query query = createNamedQuery("findTaskIntervalCycleById", startResult, maxRows, id);
			return (cn.edu.scau.cmi.hombio.domain.TaskIntervalCycle) query.getSingleResult();
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findAllTaskIntervalCycles
	 *
	 */
	@Transactional
	public Set<TaskIntervalCycle> findAllTaskIntervalCycles() throws DataAccessException {

		return findAllTaskIntervalCycles(-1, -1);
	}

	/**
	 * JPQL Query - findAllTaskIntervalCycles
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TaskIntervalCycle> findAllTaskIntervalCycles(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllTaskIntervalCycles", startResult, maxRows);
		return new LinkedHashSet<TaskIntervalCycle>(query.getResultList());
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByMemoContaining
	 *
	 */
	@Transactional
	public Set<TaskIntervalCycle> findTaskIntervalCycleByMemoContaining(String memo) throws DataAccessException {

		return findTaskIntervalCycleByMemoContaining(memo, -1, -1);
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByMemoContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TaskIntervalCycle> findTaskIntervalCycleByMemoContaining(String memo, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTaskIntervalCycleByMemoContaining", startResult, maxRows, memo);
		return new LinkedHashSet<TaskIntervalCycle>(query.getResultList());
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByFirstExecuteDate
	 *
	 */
	@Transactional
	public Set<TaskIntervalCycle> findTaskIntervalCycleByFirstExecuteDate(java.util.Calendar firstExecuteDate) throws DataAccessException {

		return findTaskIntervalCycleByFirstExecuteDate(firstExecuteDate, -1, -1);
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByFirstExecuteDate
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TaskIntervalCycle> findTaskIntervalCycleByFirstExecuteDate(java.util.Calendar firstExecuteDate, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTaskIntervalCycleByFirstExecuteDate", startResult, maxRows, firstExecuteDate);
		return new LinkedHashSet<TaskIntervalCycle>(query.getResultList());
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByCycleDays
	 *
	 */
	@Transactional
	public Set<TaskIntervalCycle> findTaskIntervalCycleByCycleDays(Integer cycleDays) throws DataAccessException {

		return findTaskIntervalCycleByCycleDays(cycleDays, -1, -1);
	}

	/**
	 * JPQL Query - findTaskIntervalCycleByCycleDays
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<TaskIntervalCycle> findTaskIntervalCycleByCycleDays(Integer cycleDays, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findTaskIntervalCycleByCycleDays", startResult, maxRows, cycleDays);
		return new LinkedHashSet<TaskIntervalCycle>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(TaskIntervalCycle entity) {
		return true;
	}
}
